package com.cheng.student.controller.servlet;

import com.cheng.student.service.TeacherServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "DeleteTeacherServlet", value = "/super/DeleteTeacherServlet")
public class DeleteTeacherServlet
        extends HttpServlet
{
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
    {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
    {
        String name = request.getParameter("name");
        String payrollNumber = request.getParameter("payrollNumber");

        if(name == null || payrollNumber == null
                || "".equals(name) || "".equals(payrollNumber))
        {
            response.getWriter().write("删除失败请检查输入信息");
            return;
        }
        //通过

        TeacherServiceImpl teacherService = new TeacherServiceImpl();

        try
        {
            teacherService.deleteTeacher(name,payrollNumber);
        }
        catch (Exception exception)
        {
            response.getWriter().write("未知原因，删除失败");
            return;
        }

        response.getWriter().write("删除成功，恭喜你");
        return;

    }
}
